//
//  HomeViewController.m
//  Teacher
//
//  Created by 李飞 on 15/10/27.
//  Copyright (c) 2015年 xueyinyue. All rights reserved.
//

#import "HomeViewController.h"
#import "MyInfoViewController.h"
#import "CheckBarcodeViewController.h"
#import "CheckBarcodeWriteViewController.h"
#import "CheckBarcodeDetailViewController.h"
#import "LessonPlanViewController.h"
#import "UserBSGetUserInfo.h"
#import "ApplicationContext.h"
#import "UIButton+WebCache.h"
#import "ApiConfig.h"
#import "User.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationItem setHidesBackButton:YES];
    self.title = @"学音悦-教师版";
    
    //设置头像圆角
    _myInfoBtn.imageView.clipsToBounds = YES;
    _myInfoBtn.imageView.layer.cornerRadius = 37;
    _myInfoBtn.enabled = NO;
    _CheckBarcodeBtn.enabled = NO;
    _CheckBarcodeWirteBtn.enabled = NO;
    _CheckBarcodeDetialBtn.enabled = NO;

    UserBSGetUserInfo *userBSGetUserInfo = [[UserBSGetUserInfo alloc] init];
   //     [self showProgressView];
    [self runService:userBSGetUserInfo andComplete:^(EACService *service) {
 //       [self hideProgressView];
    } andSuccess:^(EACService * service, id o) {
        
        UserBSGetUserInfoResult *userBSGetUserInfoResult = o;
        
        if (userBSGetUserInfoResult.isSuccess)
        {
            User *user = [ApplicationContext instance].currentUser;
            _nameLab.text = user.userName;
            _introduceLab.text = user.introduce;
            _myInfoBtn.enabled = YES;
            _CheckBarcodeBtn.enabled = YES;
            _CheckBarcodeWirteBtn.enabled = YES;
            _CheckBarcodeDetialBtn.enabled =YES;
            
           NSURL *url = [NSURL URLWithString:user.photoUrl];
            [_myInfoBtn sd_setImageWithURL:url forState:UIControlStateNormal];
            
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)onMyInfoBtnClick:(id)sender {
    
    MyInfoViewController *myInfoViewController = [[MyInfoViewController alloc] initWithNibName:@"MyInfoViewController" bundle:nil];
    myInfoViewController.isComeHome =YES;
    myInfoViewController.blockOfSetImage = ^(UIImage *headImage){
        
        [_myInfoBtn setImage:headImage forState:UIControlStateNormal];
    };
    
    [self.navigationController pushViewController:myInfoViewController animated:YES];
    
}

- (IBAction)onCheckBarcodeBtnClick:(id)sender {
    if ([[[UIDevice currentDevice] systemVersion]floatValue] >= 7)
    {
        CheckBarcodeViewController * rt = [[CheckBarcodeViewController alloc]init];
        [self presentViewController:rt animated:YES completion:^{
            
        }];
    }
    else
    {
        SHOW_ALERTVIEW(@"提示", @"7.0以上系统支持扫码功能", 1, self);
    }

}

- (IBAction)onCheckBarcodeWriteBtnClick:(id)sender {
    
    CheckBarcodeWriteViewController * checkBarcodeWriteViewController = [[CheckBarcodeWriteViewController alloc] initWithNibName:@"CheckBarcodeWriteViewController" bundle:nil];
    [self.navigationController pushViewController:checkBarcodeWriteViewController animated:YES];
}

- (IBAction)onCheckBarcodeDetialBtnClick:(id)sender {
    CheckBarcodeDetailViewController * checkBarcodeDetailViewController = [[CheckBarcodeDetailViewController alloc] initWithNibName:@"CheckBarcodeDetailViewController" bundle:nil];
    [self.navigationController pushViewController:checkBarcodeDetailViewController animated:YES];
}

- (IBAction)lessonPlanButtonClick:(id)sender
{
    LessonPlanViewController *vc = [[LessonPlanViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
